// web/src/app/(employee)/company-side/edit-employee.tsx
import React from 'react';
import {currentUser} from "@/lib/auth";
import {db} from "@/lib/db";
import CreateEmployeeForm from "@/app/(employee)/company-side/new-employee/_components/create-employee-form";
import UpdateEmployeeForm from "@/app/(employee)/company-side/edit-employee/_components/update-employee-form";

const EditEmployee = async ({searchParams}: { searchParams: { employeeId: string } }) => {
    const user = await currentUser()
    const hr = await db.hr.findFirst({
        where: {
            userId: user?.id,
        },
        include: {
            company: true
        }
    })
    if (!hr) return <div>当前用户不是公司HR账户</div>

    const cities = await db.city.findMany()
    const educations = await db.education.findMany()
    const employee = await db.employee.findUnique({
        where: {
            id: searchParams.employeeId
        },
        include: {
            tags: true
        }
    })

    return (
        <div>
            <UpdateEmployeeForm
                hr={hr}
                cities={cities}
                educations={educations}
                // @ts-ignore
                employee={employee}
            />
        </div>
    );
};

export default EditEmployee;